package com.yeban.javase.day06.test02_clone.clone1;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/10/14
 */
public class Person implements Cloneable {
    private String name;
    private int age;
    private Car car;


    public Person() {
    }

    public Person(String name, int age, Car car) {
        this.name = name;
        this.age = age;
        this.car = car;
    }

    @Override
    public Person clone() throws CloneNotSupportedException {
        // 浅拷贝：简单数据类型拷贝的是数值：引用数据类型拷贝的是地址
        Person clone = (Person)super.clone();

        // 深拷贝：无论是简单数据类型，还是引用数据类型拷贝的都是数值
        return clone;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    /**
     * 获取
     * @return car
     */
    public Car getCar() {
        return car;
    }

    /**
     * 设置
     * @param car
     */
    public void setCar(Car car) {
        this.car = car;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", car=" + car +
                '}';
    }
}
